﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Entity;
using Portal.Interface;
using MyLib;
using System.Data;
using System.Text;
using System.IO;

namespace WebPortal.YWYY
{
    public partial class ReadOnlyTB : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            copy();
        }

        public void copy()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"select * from PROC_FWDY_TIBAOSHENQING where tianrencode='{0}' and tianname='{1}'", Request.QueryString["usercode"].ToString().Trim(), Request.QueryString["tianname"].ToString().Trim());
            DataTable t = DataAccess.Instance("BizDB").ExecuteDataTable(sb.ToString());
            if (t == null && t.Rows.Count == 0)
            {
                string scriptstrs = "<script>alert('查找不到该提案名称及对应信息！');</script>";

                if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(), "welcome"))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "welcome", scriptstrs);
                }
                return;
            }
            else
            {
                tar.Text = t.Rows[0]["tianrenname"].ToString().Trim();
                tarq.Text = t.Rows[0]["tiandate"].ToString().Trim();
                szbm.Text = t.Rows[0]["tianbumen"].ToString().Trim();
                tamc.Text = t.Rows[0]["tianname"].ToString().Trim();
                tajy.Text = t.Rows[0]["tiansummary"].ToString().Trim();
                dcff.Text = t.Rows[0]["diaochaff"].ToString().Trim();
                dcqk.Text = t.Rows[0]["diaochaqk"].ToString().Trim();
                zlzl.Text = t.Rows[0]["ziliaozl"].ToString().Trim();
                string att = t.Rows[0]["ATTACHMENT"].ToString().Trim();
                attachment.Text = att.Replace(att.Substring(0, att.IndexOf("_") + 1), "");
                aa.Value = t.Rows[0]["ATTACHMENT"].ToString().Trim();
            }
        }
        //下载附件
        protected void attachment_Click(object sender, EventArgs e)
        {
            string fileName = attachment.Text;//客户端保存的文件名 
            string filePath = Server.MapPath("../PersonTB/") + aa.Value;//路径 
            //以字符流的形式下载文件 
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";
            //通知浏览器下载文件而不是打开 
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
        }
    }
}